Types
- Has 7 different types in Javascript
- number
- boolean
- string
- undefined
- null (primitive)
- Symbol()
- object
undefinedvsnullundefinedis the absence of definition- In object hoisting we use
undefined
- In object hoisting we use
nullis absence of value- Types are categorized in 2 sections
- Primitive (Represents single value)
- number
- boolean
- string
- undefined
- null (primitive)
- Symbol()
- Non-Primitive
- object
- array
- function
-
Arraytype -
typoOf []returnsobject - In JS the array is interpreted as below
js
var myArr = ['a', 'b', 'c'];
This is same as below syntax.
js
var myArr = {
0: 'a',
1: 'b',
2: 'c'
};
- Since both
objectandarrayis type ofobject, we can determine an array by using theArrayobject and itsisArray()method.
js
console.log(Array.isArray([1, 2, 3]));
console.log(Array.isArray({}));
Here the first one will print true and the second one false.